package com.huang.A03_ArrayList;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 菜品操作实体类
 * 数据的业务处理
 */
public class FoodOperator {
    //用于存放商品
    private ArrayList<Food> foodList = new ArrayList<>();

    //上架商品
    public void add(){
        //创建菜品对象 用来保存菜品数据
        Food f = new Food();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入菜品名字：");
        String name = sc.next();
        f.setName(name);
        System.out.println("请输入价格：");
        double price = sc.nextDouble();
        f.setPrice(price);
        System.out.println("请输入描述：");
        String desc = sc.next();
        f.setDesc(desc);
        //将菜品对象添加到集合中
        foodList.add(f);
        System.out.println("商品上架成功");
    }

    //展示菜品信息
    public void get(){
        if (foodList.size() == 0) {
            System.out.println("没有菜品，请先上架！！");
            return;
        }
        System.out.println("商品信息如下：");
        for (int i = 0; i < foodList.size(); i++) {
            Food f = foodList.get(i);
            System.out.println(f.getName());
            System.out.println(f.getPrice());
            System.out.println(f.getDesc());
            System.out.println("-------------");
        }
    }

    public void start(){
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("欢迎来到系统~~");
            System.out.println("1.上架商品");
            System.out.println("2.展示商品");
            System.out.println("3.退出系统");
            System.out.println("请输入您的选择");
            String option = sc.next();

            switch (option) {
                case "1":
                    add();
                    break;
                case "2":
                    get();
                    break;
                case "3":
                    return;
                default:
                    System.out.println("没有此选项，请重新选择！");
                    break;
            }
        }


    }
}